package com.oracle.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

    private static final String DATE_FORMATE = "yyyy-MM-dd HH:mm:ss";
    private static final String DATE_FORMATE2 = "yyyy-MM-dd";
    private static final String DATE_FORMATE3 = "HH:mm:ss";

    public static Date str2Date(String str){
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMATE);
        Date date = null;
        try {
            date = sdf.parse(str);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }

        return date;
    }

    public static String date2Str(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMATE);
        return sdf.format(date);
    }

    public static int d1SubD2(Date startDate,Date endDate){
        long subDay = endDate.getTime() - startDate.getTime();
        long day = subDay / 1000 / 60 / 60 / 24;
        return Integer.valueOf(day+"");
    }

}
